/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.geergenbein.azw.model.transcription;

import java.io.Serializable;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;

/**
 *
 * @author andrew
 */
@Entity
@NamedQuery(name="findDialectByName", 
    query="select d from Dialect d where name = :name")
public class Dialect implements Serializable {
    
    private static final long serialVersionUID = 1L;
    private Long id;
    private String name;
    private Set<TranscriptionSystem> transcriptionSystems;

    public Dialect() {
        
    }
    
    public Dialect(String name) {
        this.name = name;
    }
    
    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    public Long getId() {
        return id;
    }
    
    public void setId(Long id) {
        this.id = id;
    }

    @Override
    public int hashCode() {
        return new HashCodeBuilder().
                append(name).
                hashCode();
    }

    @Override
    public boolean equals(Object object) {
        if (this == object) {
            return true;
        }
        
        if (!(object instanceof Dialect)) {
            return false;
        }
        
        Dialect other = (Dialect) object;
        
        return new EqualsBuilder().
                append(name, other.getName()).
                isEquals();
    }

    @Override
    public String toString() {
        return new ToStringBuilder(this).
                append(id).
                append(name).
                toString();
    }

    @Column(unique=true, nullable=false)
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @OneToMany(cascade = CascadeType.ALL, mappedBy = "dialect")
    public Set<TranscriptionSystem> getTranscriptionSystems() {
        return transcriptionSystems;
    }

    public void setTranscriptionSystems(Set<TranscriptionSystem> transcriptionSystems) {
        this.transcriptionSystems = transcriptionSystems;
    }

}
